﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace MysqlWindowsService
{
   public  class VcEnvironmentJudgment
    {
        [DllImport("msi.dll")]
        private static extern INSTALLSTATE MsiQueryProductState(string product);
        public static INSTALLSTATE GetProcuct(string product)
        {
            INSTALLSTATE state = MsiQueryProductState(product);
            return state;
        }

        public static bool HaveInstallVc()
        {
            if (MsiQueryProductState("{13A4EE12-23EA-3371-91EE-EFB36DDFFF3E}") == INSTALLSTATE.INSTALLSTATE_DEFAULT)
                return true;
            else if (MsiQueryProductState("{F8CFEB22-A2E7-3971-9EDA-4B11EDEFC185}") == INSTALLSTATE.INSTALLSTATE_DEFAULT)
                return true;
            else if (MsiQueryProductState("{929FBD26-9020-399B-9A7A-751D61F0B942}") == INSTALLSTATE.INSTALLSTATE_DEFAULT)
                return true;
            else if (MsiQueryProductState("{A749D8E6-B613-3BE3-8F5F-045C84EBA29B}") == INSTALLSTATE.INSTALLSTATE_DEFAULT)
                return true;
            else
                return false;
        }
        public enum INSTALLSTATE
        {
            INSTALLSTATE_NOTUSED = -7,  // component disabled
            INSTALLSTATE_BADCONFIG = -6,  // configuration data corrupt
            INSTALLSTATE_INCOMPLETE = -5,  // installation suspended or in progress
            INSTALLSTATE_SOURCEABSENT = -4,  // run from source, source is unavailable
            INSTALLSTATE_MOREDATA = -3,  // return buffer overflow
            INSTALLSTATE_INVALIDARG = -2,  // invalid function argument
            INSTALLSTATE_UNKNOWN = -1,  // unrecognized product or feature
            INSTALLSTATE_BROKEN = 0,  // broken
            INSTALLSTATE_ADVERTISED = 1,  // advertised feature
            INSTALLSTATE_REMOVED = 1,  // component being removed (action state, not settable)
            INSTALLSTATE_ABSENT = 2,  // uninstalled (or action state absent but clients remain)
            INSTALLSTATE_LOCAL = 3,  // installed on local drive
            INSTALLSTATE_SOURCE = 4,  // run from source, CD or net
            INSTALLSTATE_DEFAULT = 5,  // use default, local or source
        }
    }
}
